package car;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DeleteServlet extends HttpServlet {
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	perform(req,resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	perform(req,resp);
	
	}
	private void perform(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException{
		req.setCharacterEncoding("UTF-8");
		String strIndex = req.getParameter("index");
		int index = Integer.parseInt(strIndex);
		//CarListから削除する
		CarList.remove(index);
		//一覧表を表示する（画面遷移）
		resp.sendRedirect("index.jsp");
	}
}